using Bowling.Constants;
using Bowling.Enums;

namespace Bowling;

internal class RegularFrame : Frame
{
    internal override FrameProgress Progress
    {
        get
        {
            if (FirstPins is null)
                return FrameProgress.NotStarted;
            else if (FirstPins == BowlingConstant.AllPins)
                return FrameProgress.Completed;
            else if (SecondPins is null)
                return FrameProgress.InProgress;
            else
                return FrameProgress.Completed;
        }
    }

    internal FrameType Type
    {
        get
        {
            if (FirstPins == BowlingConstant.AllPins)
                return FrameType.Strike;
            else if ((FirstPins + SecondPins) == BowlingConstant.AllPins)
                return FrameType.Spare;
            else
                return FrameType.Open;
        }
    }

    public override string Visualize()
    {
        if (Progress == FrameProgress.NotStarted)
        {
            return "[,]";
        }
        else if (Progress == FrameProgress.InProgress)
        {
            return $"[{FirstPins},]";
        }
        else
        {
            if (Type == FrameType.Strike)
            {
                return "[,x]";
            }
            else if (Type == FrameType.Spare)
            {
                return $"[{FirstPins},/]";
            }
            else if (Type == FrameType.Open)
            {
                return $"[{FirstPins},{SecondPins}]";
            }
            else
                return string.Empty;
        }
    }
}
